package cn.shengchao.examstar.rpc.product.base;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: examstarapi
 * @description: 内容产品结构
 * @author: Xiong weiqiang
 * @create: 2025-06-10 16:27
 */
public class ContentProductStruct implements Serializable {
    private static List<ProductTypeTree> productTypeTrees;
    private static Map<String,List<SimpleProduct>> productMapList;
    static  {
        productTypeTrees = new ArrayList<>();
        ProductTypeTree productTypeTree1 = ProductTypeTree.builder()
                .typeId(ContentProductType.COURSE.name())
                .typeName("课程")
                .children(new ArrayList<>())
                .build();
        ProductTypeTree productTypeTree2 = ProductTypeTree.builder()
                .typeId(ContentProductType.THIRD_MEMBER.name())
                .typeName("三方会员")
                .children(new ArrayList<>())
                .build();
        ProductTypeTree productTypeTree21 = ProductTypeTree.builder()
                .typeId("PRODUCT_THIRD_CAP")
                .typeName("育腾")
                .children(new ArrayList<>())
                .build();
        ProductTypeTree productTypeTree211 = ProductTypeTree.builder()
                .typeId("1903349492701995668")
                .typeName("高考会员")
                .children(new ArrayList<>())
                .build();
        productTypeTree21.setChildren(List.of(productTypeTree211));
        ProductTypeTree productTypeTree22 = ProductTypeTree.builder()
                .typeId("PRODUCT_THIRD_YCBDC")
                .typeName("忆成会员")
                .children(new ArrayList<>())
                .build();
        ProductTypeTree productTypeTree221 = ProductTypeTree.builder()
                .productId(1903349492891995601L)
                .typeId("PRODUCT_THIRD_YCBDC")
                .typeName("忆成会员（包月）")
                .children(new ArrayList<>())
                .build();
        ProductTypeTree productTypeTree222 = ProductTypeTree.builder()
                .productId(1903349492891995602L)
                .typeId("PRODUCT_THIRD_YCBDC")
                .typeName("忆成会员（季度）")
                .children(new ArrayList<>())
                .build();
        ProductTypeTree productTypeTree223 = ProductTypeTree.builder()
                .productId(1903349492891995603L)
                .typeId("PRODUCT_THIRD_YCBDC")
                .typeName("忆成会员（一年）")
                .children(new ArrayList<>())
                .build();
        productTypeTree22.setChildren(List.of(productTypeTree221,  productTypeTree222, productTypeTree223));
        productTypeTree2.setChildren(List.of(productTypeTree21, productTypeTree22));
        productTypeTrees.add(productTypeTree1);
        productTypeTrees.add(productTypeTree2);
        productMapList =new HashMap<>();
        productMapList.put("COURSE",List.of());
        productMapList.put("PRODUCT_THIRD_YCBDC",List.of(SimpleProduct.builder()
                .productId(1903349492891995601L)
                .productName("忆成会员(包月)")
                .productType("PRODUCT_THIRD_YCBDC")
                .build(),SimpleProduct.builder()
                        .productId(1903349492891995602L)
                        .productName("忆成会员(季度)")
                        .productType("PRODUCT_THIRD_YCBDC")
                        .build(),SimpleProduct.builder()
                        .productId(1903349492891995603L)
                        .productName("忆成会员(一年)")
                        .productType("PRODUCT_THIRD_YCBDC")
                        .build())
                );
        productMapList.put("PRODUCT_THIRD_CAP",List.of(SimpleProduct.builder()
                .productId(1903349492701995668L)
                .productName("高考志愿会员")
                .productType("PRODUCT_THIRD_CAP")
                .build())
        );
    }

    public static List<ProductTypeTree> getProductTypeTrees() {
        return productTypeTrees;
    }


    public static SimpleProduct getSimpleProductById(Long productId) {
        if (productMapList==null) return null;
        for (String key: productMapList.keySet()){
            for (SimpleProduct simpleProduct: productMapList.get(key)){
                if (simpleProduct.getProductId().equals(productId)){
                    return simpleProduct;
                }
            }
        }
        return null;
    }

    public static List<SimpleProduct> getSimpleProductList(List<String> productTypes) {
        List<SimpleProduct>  simpleProducts = new ArrayList<>();
        if (productMapList==null) return null;
        for (String key: productMapList.keySet()){
            if (productTypes.contains( key)){
                simpleProducts.addAll(productMapList.get(key));
            }
        }
        return simpleProducts;
    }
}